package com.xposed.aliproxy.xposed;

import android.content.Context;
import android.content.Intent;

import com.xposed.aliproxy.db.AliTradeModel;
import com.xposed.aliproxy.utils.ActionUtil;
import com.xposed.aliproxy.utils.XposeUtil;

import java.io.Serializable;
import org.json.JSONArray;
import org.json.JSONObject;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

public class AliHookMethodb extends XC_MethodHook {
    private ClassLoader classLoader;
    private Context context;

    public AliHookMethodb(Context context, ClassLoader classLoader) {
        this.context = context;
        this.classLoader = classLoader;
    }

    @Override
    protected void beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable {
        try {
            String str = (String) XposedHelpers.callMethod(methodHookParam.args[0], "toString", new Object[0]);
            String b = XposeUtil.m3001b(str, "content='", "'");
            str = XposeUtil.m3001b(str, "extraInfo='", "'");
            XposeUtil.xposedLog("AliHookMethod3_content->", b);
            XposeUtil.xposedLog("AliHookMethod3_extraInfo->", str);
            String str2 = "";
            String str3 = "";
            String str4 = "";
            String str5 = "";
            String str6 = "1";
            if (b.contains("二维码收款") || b.contains("收到一笔转账") || b.contains("提现")) {
                JSONObject jSONObject = new JSONObject(str);
                JSONArray jSONArray = jSONObject.getJSONArray("content");
                String string = jSONObject.getString("money");
                b = XposeUtil.m3001b(jSONObject.getString("goto"), "tradeNO", "&").replaceAll("=", "");
                String str7 = str6;
                str6 = str3;
                str3 = str2;
                for (int i = 0; i < jSONArray.length(); i++) {
                    JSONObject jSONObject2 = jSONArray.getJSONObject(i);
                    String string2 = jSONObject2.getString("title");
                    String string3 = jSONObject2.getString("content");
                    if ("付款人：".equals(string2) || "付款方：".equals(string2)) {
                        String[] split = string3.split(" ");
                        str6 = split[0];
                        str5 = split[1];
                    } else if ("收款理由：".equals(string2) || ("转账备注：".equals(string2) && "".equals(str3))) {
                        str3 = string3;
                    } else if (string2.contains("到账时间")) {
                        str4 = string3;
                    } else if ("提现到：".equals(string2)) {
                        str3 = "提现";
                        str7 = "2";
                        str6 = string3;
                    } else if ("提现说明：".equals(string2)) {
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.append(string3);
                        stringBuilder.append("提现");
                        str3 = stringBuilder.toString();
                    }
                }
                str = string.replaceAll("元", "").replaceAll(",", "").trim();
                JSONObject jSONObject3 = new JSONObject();
                jSONObject3.put("date", str4);
                jSONObject3.put("money", str);
                jSONObject3.put("remark", str3);
                jSONObject3.put("outAliId", str5);
                jSONObject3.put("tradeNo", b);
                jSONObject3.put("name", str6);
                XposeUtil.xposedLog("tradeDetail2->", jSONObject3.toString());
                AliTradeModel aliTradeModel = new AliTradeModel();
                aliTradeModel.setDate(str4);
                aliTradeModel.setAmount(str);
                aliTradeModel.setRemark(str3);
                aliTradeModel.setOutAliId(str5);
                aliTradeModel.setTradeNo(b);
                aliTradeModel.setName(str6);
                aliTradeModel.setType(str7);
                aliTradeModel.setStatus("0");
                Intent intent = new Intent(ActionUtil.RECEIVER_TRADE_MODEL);
                intent.putExtra("aliTradeModel", aliTradeModel);
                intent.putExtra("isMer", false);
                this.context.sendBroadcast(intent);
            }
        } catch (Throwable th) {
            th.printStackTrace();
            XposedBridge.log(th);
        }
        super.beforeHookedMethod(methodHookParam);
    }
}
